import React, { useState, useRef } from "react";

const Counter: React.FC = () => {
  const [show, setShow] = useState(true);
  const ref = useRef<HTMLParagraphElement>(null);

  return (
    <div>
      <button
        onClick={() => {
          setShow(!show);
        }}
      >
        通过setState切换
      </button>
      <button
        onClick={() => {
          ref.current?.remove();
        }}
      >
        从DOM中删除
      </button>
      {show && <p ref={ref}>Hello world</p>}
    </div>
  );
};
export default Counter;
